package huas.ant.mapper;

import com.github.pagehelper.Page;
import huas.ant.entity.Lesson;
import huas.ant.vo.LessonVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LessonMapper {
    /**
     * 分页列表查询
     */
    @Select("select * from lesson")
    public Page<Lesson> page();

    /**
     * 使主键从当前最大的值开始自增（可以解决部分自增不连续问题）
     */
    @Update("ALTER TABLE lesson AUTO_INCREMENT = 1")
    void reset();
    /**
     * 添加课程
     */
    @Insert("insert into lesson (name, begin, time, coach_id) values (#{name},#{begin},#{time},#{coachId}) ")
    void insert(Lesson lesson);
    /**
     * 修改课程
     */
    void update(Lesson lesson);
    /**
     * 删除课程
     */
    @Delete("delete from lesson where id = #{id}")
    void delete(Integer id);

    /**
     * 回写课程的详细信息,多表查询
     */
    @Select("select m.name from lesson l left join member m on l.id = m.lesson_id where l.id = #{id}")
    List<String> selectDetails(Integer id);

    @Select("select c.name from lesson l left join coach c on c.id = l.coach_id where l.id = #{id}")
    String selectCoach(Integer id);
}
